package top.sdaily.web.controller.sys;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.sdaily.core.mybatis.Page;
import top.sdaily.web.context.ReturnBody;
import top.sdaily.web.model.Role;
import top.sdaily.web.service.RoleService;

/**
 * Created by tsujishiki on 2017/1/22.
 */
@RestController
@RequestMapping("role")
public class RoleController {

    @Autowired
    RoleService roleService;

    @GetMapping
    public ReturnBody getRoles() {
        return ReturnBody.success().setData(roleService.getAll());
    }

    @GetMapping(value = "/{id}")
    public ReturnBody getRoleById(@PathVariable String id) {
        return ReturnBody.success().setData(roleService.getRoleById(id));
    }

    @PostMapping
    public ReturnBody addRole(@RequestBody Role role) {
        roleService.insertRole(role);
        return ReturnBody.success();
    }

    @PutMapping
    public ReturnBody updateRole(@RequestBody Role role) {
        roleService.updateRole(role);
        return ReturnBody.success();
    }
}
